package kr.saeildamil.androidstudy_second.valueani;

import kr.saeildamil.andrordstudy.second.R;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class ValueAnimatorTest2 extends Activity {
	Button mBtn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch24_valueanimator);
		mBtn=(Button) findViewById(R.id.ch24_btn);
	}
	
	public void mOnClick(View v){
		ValueAnimator anim = ValueAnimator.ofInt(150, 480);
		anim.setDuration(2000);
		anim.setInterpolator(null);//Linear
		anim.setRepeatCount(1);
		anim.setRepeatMode(ValueAnimator.REVERSE);
		anim.addListener(new AnimatorListenerAdapter() {
			public void onAnimationEnd(Animator animation) {
				super.onAnimationEnd(animation);
				Toast.makeText(ValueAnimatorTest2.this, "end", Toast.LENGTH_SHORT).show();
			}
			public void onAnimationStart(Animator animation) {
				super.onAnimationStart(animation);
				Toast.makeText(ValueAnimatorTest2.this, "start", Toast.LENGTH_SHORT).show();
			}
			
		});
		anim.addUpdateListener(new AnimatorUpdateListener() {
			public void onAnimationUpdate(ValueAnimator animation) {
				mBtn.setWidth((Integer)animation.getAnimatedValue());
			}
		});
		anim.start();
	}
}
